add babl_format_is_palette
authorØyvind Kolås <pippin@gimp.org>
Wed, 21 Mar 2012 18:13:38 +0000 (18:13 +0000)
committerØyvind Kolås <pippin@gimp.org>
Wed, 21 Mar 2012 18:14:09 +0000 (18:14 +0000)
babl/babl-format.h
babl/babl-palette.c
babl/babl.h

index 01f8f12b84b8d5d8458110fe72cfba5bc78d95f5..bc78f4232c7a8bc5531607003bcf2463ebaccbab 100644 (file)
@@ -41,6 +41,7 @@ typedef struct
   int              visited; /* for convenience in code while searching
                                for conversion paths */
   int              format_n; /* whether the format is a format_n type or not */
+  int              palette;
 } BablFormat;
 
 #endif
index 4655211d3384d27e1d4be74560bf623316233bb6..8639ba9244fb193de83f0c63ef372dd0ba5a3a84 100644 (file)
 #include <stdio.h>
 #include <values.h>
 #include <assert.h>
+#include "config.h"
+#include "babl-internal.h"
 #include "babl.h"
 #include "babl-memory.h"
 
 #define HASH_TABLE_SIZE 1111
 
-void babl_sanity (void);
-
 /* A default palette, containing standard ANSI / EGA colors
  *
  */
@@ -446,6 +446,14 @@ conv_pala8_pal8 (unsigned char *src, unsigned char *dst, long samples)
   return samples;
 }
 
+int
+babl_format_is_palette (const Babl *format)
+{
+  if (format->class_type == BABL_FORMAT)
+    return format->format.palette;
+  return 0;
+}
+
 /* should return the BablModel, permitting to fetch
  * other formats out of it?
  */
@@ -455,8 +463,8 @@ const Babl *babl_new_palette (const char  *name,
 {
   const Babl *model;
   const Babl *model_no_alpha;
-  const Babl *f_pal_u8;
-  const Babl *f_pal_a_u8;
+  Babl *f_pal_u8;
+  Babl *f_pal_a_u8;
   const Babl *component;
   const Babl *alpha;
   BablPalette **palptr;
@@ -490,14 +498,17 @@ const Babl *babl_new_palette (const char  *name,
   cname[0] = 'v';
   model_no_alpha = babl_model_new ("name", name, component, NULL);
   cname[0] = 'x';
-  f_pal_a_u8 = babl_format_new ("name", name, model,
+  f_pal_a_u8 = (void*) babl_format_new ("name", name, model,
                                 babl_type ("u8"),
                                 component, alpha, NULL);
   cname[0] = 'y';
-  f_pal_u8  = babl_format_new ("name", name, model_no_alpha,
+  f_pal_u8  = (void*) babl_format_new ("name", name, model_no_alpha,
                                babl_type ("u8"),
                                component, NULL);
 
+  f_pal_a_u8->format.palette = 1;
+  f_pal_u8->format.palette = 1;
+
   babl_conversion_new (
      model,
      babl_model ("RGBA"),
index 019b7b9a38700b9c03ca43589843572bb99c5e42..80333c0917567442b79ec30fbf8e1bd62080085e 100644 (file)
@@ -210,6 +210,11 @@ const Babl *babl_new_palette (const char  *name,
                               const Babl **format_u8,
                               const Babl **format_u8_with_alpha);
 
+/**
+ * check whether a format is a palette backed format.
+ */
+int   babl_format_is_palette   (const Babl *format);
+
 /**
  * Assign a palette to a palette format, the data is a single span of pixels
  * representing the colors of the palette.
@@ -220,15 +225,18 @@ void  babl_palette_set_palette (const Babl        *babl,
                                 int                count);
 
 /**
- * reset a palette to initial state.
+ * reset a palette to initial state, frees up some caches that optimize
+ * conversions.
  */
 void  babl_palette_reset       (const Babl        *babl);
 
 
+
 /**
  * associate a data pointer with a format/model, this data can be accessed and
  * used from the conversion functions, encoding color profiles, palettes or
- * similar with the data.
+ * similar with the data, perhaps this should be made internal API, not
+ * accesible at all from
  */
 void   babl_set_user_data     (const Babl *babl, void *data);